﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using Telerik.Windows.Controls;
using System.Threading;

namespace Health_Solution
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        
        
        private void InitializeShell()
        {
            StyleManager.ApplicationTheme = new Windows7Theme();
        }
        Thread t;
        public App()
        {
            t = new Thread(new ParameterizedThreadStart(fun));
            this.Exit += new ExitEventHandler(App_Exit);
            t.Start();
            InitializeShell();
            this.DispatcherUnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException);
        }

        void App_Exit(object sender, ExitEventArgs e)
        {
            if (t != null)
            {
                if (t.ThreadState != ThreadState.Stopped)
                    t.Abort();
            }
        }

        void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            if (!System.Diagnostics.Debugger.IsAttached)
            {
                e.Handled = true;
                this.Dispatcher.BeginInvoke(new Action(() =>
                {
                    MessageBox.Show(e.Exception.Message, "错误信息");
                    //MessageBox.Show(e.Exception.Message + "\r\n" + e.Exception.StackTrace, "错误信息");
                }), null);
            }
        }

        void fun(object o)
        {
            Random r = new Random();
            int val = r.Next(-200, 200);
            Thread.Sleep((1000 + val)*1000);
            Dispatcher.Invoke(new Action(() => App.Current.Shutdown()));
        }
    }
}
